home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
datecls.exe
/
DATECLS4.H
< prev
next >
Wrap
C/C++ Source or Header
|
1993-03-07
|
6KB
|
166 lines
/*
*┌──────────────────────────────────────────────────────────────────────
*│ File.........: DATECLS4.H
*│ Date.........: Sunday 3/7/1993
*│ Author.......: Kenneth A. Argo (CIS 71241,3635)
*│ Copyright....: None! Use freely.
*│ Version......: 4.1 Compile w/MSC++ 7.0
*│ Usage........: General purpose date conversion, arithmetic,
*│ : comparison, and formatting class
*│ Compile line.: cl /AM /W3 /Zp /D_DOS /Osel /Gs /c datecl4.cpp
*│ : cl /AM /W3 /Zp /D_DOS /Osel /Gs /c datedemo.cpp
*│ Link line....:
*│ link /NOD /ONERROR:NOEXE datedemo date, datedemo, NUL, mafxcr mlibce;
*│
*│ Acknowledgements:
*│
*│ Originally inspired by Steve Marcus (CIS 72007,1233) 6/16/91
*│ Enhanced by Eric Simon (CIS 70540,1522) 6/29/91
*│ Further Enhanced by Chris Hill (CIS 72030,2606) 7/11/91
*│ Still Further Enhanced by Hill & Simon v3.10 8/05/91
*│
*│ "It just keeps on a 'git 'n bedder!"
*│ by Charles D. Price (CIS 70541,3651) v4.0 6/27/92
*│
*│ Sealing the memory leaks...
*│ some variable casts and string output.
*│ by Kenneth A. Argo (CIS 71241,3635) v4.1 3/10/93
*│
*│ And the quest for the perfect date class continues....
*│
*└──────────────────────────────────────────────────────────────────────
*/
#ifndef __cplusplus
#error Requires C++ Compiler
#endif
#ifndef DATECLS_H
#define DATECLS_H
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream.h>
#include <dos.h>
#define PUBLIC // just a couple of friendly reminders!
#define MEMBER
#define ABBR_LENGTH 3
const enum format_type {MDY, DAY, MONTH, FULL, EUROPEAN};
const enum {OFF, ON};
const unsigned char NO_CENTURY = 0x02;
const unsigned char DATE_ABBR = 0x04;
const char BadDate[] = "invalid date"; // so we don't repeat for every "INVALID" Date object !
class Date
{
protected:
unsigned long julian; // see julDate(); days since 1/1/4713 B.C.
unsigned int year; // see NYear4()
unsigned char month; // see NMonth()
unsigned char day; // see Day()
unsigned char day_of_week; // see NDOW(); 1 = Sunday, ... 7 = Saturday
char *buf; // easier to track memory leaks if we only have 1 pointer
private:
static int DisplayFormat;
static unsigned char DisplayOptions;
void julian_to_mdy (); // convert julian day to mdy
void julian_to_wday (); // convert julian day to day_of_week
void mdy_to_julian (); // convert mdy to julian day
public:
Date ();
Date (const long j);
Date (const int m, const int d, const int y);
Date (char *dat);
Date (const _dosdate_t &ds);
Date (const Date &dt);
~Date();
operator char * (void);
Date &operator + (const long i);
Date &operator + (const int i);
Date &operator - (const long i);
Date &operator - (const int i);
long operator - (const Date &dt);
Date &operator += (const long i);
Date &operator -= (const long i);
Date &operator ++ (); // Prefix increment
Date &operator ++ (int); // Postfix increment
Date &operator -- (); // Prefix decrement
Date &operator -- (int); // Postfix decrement
friend int operator < (const Date &dt1, const Date &dt2);
friend int operator <= (const Date &dt1, const Date &dt2);
friend int operator > (const Date &dt1, const Date &dt2);
friend int operator >= (const Date &dt1, const Date &dt2);
friend int operator == (const Date &dt1, const Date &dt2);
friend int operator != (const Date &dt1, const Date &dt2);
friend ostream &operator << (ostream &os, const Date &dt);
friend ostream &operator << (ostream &os, const _dosdate_t &dt);
char *formatDate(const int type=DisplayFormat) const;
static void setFormat (const int format);
static int setOption (const int option, const int action=ON);
long julDate() const; // returns julian date
int DOY() const; // returns relative date since Jan. 1
int isLeapYear() const; // returns 1 if leap year, 0 if not
// note that the next functions return a date struct as defined in
// dos.h (distinct from the Date class)
_dosdate_t eom() const; // returns last day of month in object
_dosdate_t getDate() const; // returns a date structure
//─────────────────────────────────────────────────
// Version 4.0 Extension to Public Interface - CDP
//─────────────────────────────────────────────────
// Theses 'Set's modify the date object and actually SET it
// They all return a reference to self (*this)
Date &Set(); // Sets to current system date
Date &Set(long lJulian);
Date &Set(int nMonth, int nDay, int nYear);
Date &AddWeeks(int nCount = 1); //
Date &AddMonths(int nCount = 1); // May also pass neg# to decrement
Date &AddYears(int nCount = 1); //
int Day() const; // Numeric Day of date object
int DaysInMonth(); // Number of days in month (1..31)
int FirstDOM() const; // First Day Of Month (1..7)
char *CDOW(); // Character Day Of Week ('Sunday'..'Saturday')
int NDOW() const; // (1..7)
int WOM(); // Numeric Week Of Month (1..6)
int WOY(); // Numeric Week Of Year (1..52)
char *CMonth(); // Character Month name
int NMonth() const; // Month Number (1..12)
Date BOM(); // First Date Of Month
Date EOM(); // Last Date Of Month
int NYear4() const; // eg. 1992
Date BOY(); // First Date Of Year
Date EOY(); // Last Date Of Year
};
#endif